/* This file is part of the Crimsoon project
  * Copyright (C) 2009 Eduardo Henrique <eduardohleite@gmail.com>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Library General Public
  * License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Library General Public License for more details.
  *
  * You should have received a copy of the GNU Library General Public License
  * along with this library; see the file COPYING.LIB.  If not, write to
  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  * Boston, MA 02110-1301, USA.
*/

#include "infopanel.h"
#include "gallery.h"
#include "musicfile.h"
#include "util.h"

#include <QImage>
#include <QLabel>
#include <QVBoxLayout>
#include <QFormLayout>
#include <QFont>

void InfoPanel::refresh(QString path)
{
    Gallery gallery;
    MusicFile currentFile;

    currentFile = gallery.getMusicFileInfo(path);
    imageWidget->setImage(currentFile.picture);
    titleLabel->setText(currentFile.title);
    artistLabel->setText(currentFile.artist);
    albumLabel->setText(currentFile.album);
    trackLabel->setText(QString::number(currentFile.track));
    genreLabel->setText(currentFile.genre);
    yearLabel->setText(QString::number(currentFile.year));
    bitrateLabel->setText(QString::number(currentFile.bitRate) + " Kbps");
    lengthLabel->setText(calculateLength(currentFile.length));

}

void InfoPanel::createWidgets()
{
    QFont font;

    mainLayout  = new QVBoxLayout;
    imageWidget = new ImageWidget(120,120);

    mainLayout->addWidget(imageWidget);
    mainLayout->addSpacing(30);

    titleLabel   = new QLabel;
    artistLabel  = new QLabel;
    albumLabel   = new QLabel;
    trackLabel   = new QLabel;
    genreLabel   = new QLabel;
    yearLabel    = new QLabel;
    bitrateLabel = new QLabel;
    lengthLabel  = new QLabel;

    detailsLayout = new QFormLayout;

    detailsLayout->addRow("Title: "  , titleLabel);
    detailsLayout->addRow("Artist: " , artistLabel);
    detailsLayout->addRow("Album: "  , albumLabel);
    detailsLayout->addRow("Track #: ", trackLabel);
    detailsLayout->addRow("Genre: "  , genreLabel);
    detailsLayout->addRow("Year: "   , yearLabel);
    detailsLayout->addRow("Bitrate: ", bitrateLabel);
    detailsLayout->addRow("Lenght: " , lengthLabel);

    mainLayout->addLayout(detailsLayout);

    setLayout(mainLayout);
}

InfoPanel::InfoPanel()
{
    setFixedWidth(200);
    createWidgets();
}

InfoPanel::~InfoPanel()
{
    delete mainLayout;
    delete detailsLayout;
    delete imageWidget;
    delete titleLabel;
    delete artistLabel;
    delete albumLabel;
    delete trackLabel;
    delete genreLabel;
    delete yearLabel;
    delete bitrateLabel;
    delete lengthLabel;
}
